<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\model\PortalDemoModel;
use cmf\controller\HomeBaseController;
use think\facade\Db;
use think\Model;

class DemoController extends HomeBaseController
{

    /**
     * 文章详情
     * @return mixed
     * User: sunc
     * Date: 2021/6/22 14:02
     */
    public function index()
    {

        $portalPostModel = new PortalDemoModel();

        $articleId = $this->request->param('id', 0, 'intval');

        $where = [
            'id' => $articleId
        ];

        $article = $portalPostModel->field('*')
            ->where($where)
            ->find();

        if (empty($article)) {
            abort(404, '文章不存在!');
        }

        $tplName = 'demo';


        $this->assign('article', $article);

        return $this->fetch("/$tplName");
    }


    /**
     * 分页列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * User: sunc
     * Date: 2021/6/22 14:18
     */
    public function list()
    {
        $pageId = $this->request->param('page_id', 0, 'intval');
        $pageSize = 20;
        $demo = Db::name('demo')->order('list_order DESC')->limit($pageSize * $pageId, $pageSize)->select()->toArray();
        $this->assign('demo', $demo);
        return $this->fetch('/list');
    }

}